//
//  VipPopView.m
//  AILove
//
//  Created by 甘世清 on 2023/12/15.
//

#import "VipPopView.h"
#import "VipViewController.h"
@implementation VipPopView

- (void)SQ_UIViewForSelfView{
    UIImageView * image = [[UIImageView alloc]init];
    image.image = SQGetImage(@"vippop背景");
    image.contentMode = UIViewContentModeScaleAspectFit;
    [self addSubview:image];
    [image mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(256);
            make.height.mas_equalTo(286);
            make.centerX.centerY.equalTo(self);
    }];
    
    UILabel * top = [[UILabel alloc]init];
    top.text = SQNSLocalString(@"开通VIP会员");
    top.textColor = SQColor(@"#363847");
    top.font = FONT_BOLD(14);
    [image addSubview:top];
    [top mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(image);
            make.top.equalTo(image);
            make.height.mas_equalTo(22);
    }];
    UILabel * top1 = [[UILabel alloc]init];
    top1.text = SQNSLocalString(@"开通VIP会员\n解锁全部特权");
    top1.textColor = SQColor(@"#ffffff");
    top1.numberOfLines = 0;
    top1.font = FONT_BOLD(16);
    [image addSubview:top1];
    [top1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(image);
            make.top.equalTo(image).offset(34);
            make.height.mas_equalTo(40);
    }];
    
    UILabel * top2 = [[UILabel alloc]init];
    top2.text = SQNSLocalString(@"解锁角色互动 永久实时更新");
    top2.textColor = SQColor(@"#FCE9D6");
    top2.font = FONT_MEDIUM(12);
    [image addSubview:top2];
    [top2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(image);
            make.top.equalTo(image).offset(84);
            make.height.mas_equalTo(26);
    }];
    
    UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setTitle:SQNSLocalString(@"立即开通") forState:normal];
    btn.titleLabel.font = FONT_BOLD(16);
    [btn setTitleColor:SQColor(@"#363847") forState:normal];
    btn.backgroundColor = UIColor.clearColor;
    [btn addTarget:self action:@selector(SQ_buttonClick) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self);
            make.width.mas_equalTo(200);
            make.height.mas_equalTo(40);
            make.top.equalTo(image).offset(228);
    }];
    
    _guanbi = [[SQCustomButton alloc]initType:SQCustomButtonTopImageType imageSize:CGSizeMake(15, 15) midmargin:0];
    _guanbi.image = SQGetImage(@"退出图标");
    [self addSubview:self.guanbi];
    [self.guanbi mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self);
            make.top.equalTo(image.mas_bottom);
            make.size.mas_equalTo(46);
    }];
    WS(weakSelf);
    [self.guanbi setTouchBlock:^(SQCustomButton * _Nonnull button) {
            if (weakSelf.VipBlock) {
                weakSelf.VipBlock();
            }
    }];
    [self SQ_header];
}
-(void)SQ_buttonClick{
    if (self.VipBlock) {
        self.VipBlock();
    }
    VipViewController * vc = [[VipViewController alloc]init];
    [[Manager SQ_getCurrentViewController].navigationController pushViewController:vc animated:YES];
}

-(void)SQ_header{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    [dic setObject:@"vip_switch" forKey:@"key"];
    [HttpTool post:Url7 paramDic:dic successBlock:^(BaseModel * _Nonnull httpModel) {
        NSDictionary * data = [[NSDictionary alloc]initWithDictionary:httpModel.data];
        NSString* value = [NSString stringWithFormat:@"%@",[data objectForKey:@"value"]];
        if ([value isEqualToString:@"0"]) {
            self.guanbi.hidden = YES;
        } else {
            self.guanbi.hidden = NO;
        }
        } andFailBloc:^(BaseModel * _Nonnull httpModel, NSError * _Nullable error) {
            
        }];
}
@end
